#include "sgame.h"
/******SGUI 移动房间模板*******

*****************************/
//移动房间
sRoom**sgame_rmpStr;
sRoom**sgame_rmpEnd;

//全局房间
sRoom*sgame_rmMove;
int sgame_moveType;

//房间创建
void sgame_moveCreate(void*rm)
{
 //改变视野
 if(sgame_moveType==_RIGHT)
 {
  (*sgame_rmpStr)->cam.x = 0;
  (*sgame_rmpEnd)->cam.x = -SW;
 }
 else
 {
  (*sgame_rmpStr)->cam.x = 0;
  (*sgame_rmpEnd)->cam.x = SW;
 }
}

//绘制房间
void sgame_moveDraw(void*rm)
{
 sRoom*room = rm;
 sDrawSenObjCam(room->sen,
  &(room->cam));
 sRoom**rmpStr = sgame_rmpStr;
 sRoom**rmpEnd = sgame_rmpEnd;
 
 //绘制两个过渡房间
 if((*rmpStr)->draw!=NULL)
 {
  _room = *rmpStr;
  (*rmpStr)->draw(*rmpStr);
 }
 else
 	sDrawSenObjCam(
  (*rmpStr)->sen,
  &(*rmpStr)->cam);
 
 if((*rmpEnd)->draw!=NULL)
 {
  _room = *rmpEnd;
  (*rmpEnd)->draw(*rmpEnd);
 }
 else
 	sDrawSenObjCam((*rmpEnd)->sen,
  &(*rmpEnd)->cam);
 _room = sgame_rmMove;
 
 if(sgame_moveType==_RIGHT)
 {
  //移动两个房间
  (*rmpStr)->cam.x+=60;
  (*rmpEnd)->cam.x+=40;
  //移动到位
  if((*rmpEnd)->cam.x>=0)
  {
   //跳转页面
   (*rmpStr)->cam.x = 0;
   (*rmpEnd)->cam.x = 0;
   
   sExitRoom(*rmpStr);
   _room = *rmpEnd;
   
   *rmpStr = NULL;
   return;
  }
 }
 else
 {
  //移动两个房间
  (*rmpStr)->cam.x-=60;
  (*rmpEnd)->cam.x-=40;
  //移动到位
  if((*rmpEnd)->cam.x<=0)
  {
   //跳转页面
   (*rmpStr)->cam.x = 0;
   (*rmpEnd)->cam.x = 0;
   
   sExitRoom(*rmpStr);
   _room = *rmpEnd;
   
   *rmpStr = NULL;
   return;
  }
 }
}
//房间事件
void sgame_moveEvent(int type,int p1,int p2)
{
 
}

//跳转房间 左右上下
int sgame_gotoMove(sRoom**str,sRoom**end,int type)
{
 //接收数据
 sgame_rmpStr = str;
 sgame_rmpEnd = end;
 sgame_moveType = type;
 
 //sRoom**rmpStr = sgame_rmpStr;
 sRoom**rmpEnd = sgame_rmpEnd;
 
 //创建房间
 if((*rmpEnd)->create!=NULL)
 	(*rmpEnd)->create(*rmpEnd);
 
 if(sgame_rmMove==NULL)
 {
  sgame_rmMove = 
  sNewRoom(SW,SH,100);
 }
 sgame_rmMove->create = 
 sgame_moveCreate;
 sgame_rmMove->draw = 
 sgame_moveDraw;
 sgame_rmMove->event = 
 sgame_moveEvent;
 sGotoRoom(sgame_rmMove);
 return 0;
}
